import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useHotelStore = defineStore('hotel', () => {
  const hotels = ref([])
  const currentHotel = ref(null)
  const loading = ref(false)

  // 获取酒店列表
  const fetchHotels = async (params = {}) => {
    loading.value = true
    try {
      // 模拟API调用
      setTimeout(() => {
        hotels.value = [
          {
            id: 1,
            name: '北海大酒店',
            start: 4.5,
            addr: '北海市海城区银滩路步行街231号',
            price: 299,
            images: ['https://q7.itc.cn/q_70/images03/20240506/06d5954320e247ef99d7bac9530ba7be.jpeg']
          }
        ]
        loading.value = false
      }, 1000)
    } catch (error) {
      loading.value = false
      throw error
    }
  }

  // 设置当前酒店
  const setCurrentHotel = (hotel) => {
    currentHotel.value = hotel
  }

  return {
    hotels,
    currentHotel,
    loading,
    fetchHotels,
    setCurrentHotel
  }
})